package com.ruoyi.web.controller.depot;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.depot.domain.Receipt;
import com.ruoyi.depot.domain.vo.QualityInspectionDetailVO;
import com.ruoyi.depot.domain.vo.QualityInspectionVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.depot.domain.QualityInspection;
import com.ruoyi.depot.service.IQualityInspectionService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 品检Controller
 * 
 * @author luxiaoyu
 * @date 2024-11-05
 */
@RestController
@RequestMapping("/depot/inspection")
public class QualityInspectionController extends BaseController
{
    @Autowired
    private IQualityInspectionService qualityInspectionService;

    /**
     * 查询品检列表
     */
    @PreAuthorize("@ss.hasPermi('depot:inspection:list')")
    @GetMapping("/list")
    public TableDataInfo list(QualityInspection qualityInspection)
    {
        startPage();
        List<QualityInspectionVO> list = qualityInspectionService.selectQualityInspectionList(qualityInspection);
        return getDataTable(list);
    }

    /**
     * 导出品检列表
     */
    @PreAuthorize("@ss.hasPermi('depot:inspection:export')")
    @Log(title = "品检", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QualityInspection qualityInspection)
    {
        List<QualityInspectionVO> list = qualityInspectionService.selectQualityInspectionList(qualityInspection);
        ExcelUtil<QualityInspectionVO> util = new ExcelUtil<QualityInspectionVO>(QualityInspectionVO.class);
        util.exportExcel(response, list, "品检数据");
    }

    /**
     * 获取品检详细信息
     */
    @PreAuthorize("@ss.hasPermi('depot:inspection:query')")
    @GetMapping(value = "/{inspectionId}")
    public AjaxResult getInfo(@PathVariable("inspectionId") String inspectionId)
    {
        return success(qualityInspectionService.selectQualityInspectionByInspectionId(inspectionId));
    }


    /**
     * 根据产品id查询库存次品量详细
     * @param vo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('depot:inspection:query')")
    @GetMapping(value = "/product/getDefectiveQuantityDetails")
    public TableDataInfo getProductInfo(QualityInspectionDetailVO vo)
    {
        startPage();
        return getDataTable(qualityInspectionService.selectQualityInspectionByProductId(vo));
    }

    /**
     * 新增品检
     */
    @PreAuthorize("@ss.hasPermi('depot:inspection:add')")
    @Log(title = "品检", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QualityInspection qualityInspection)
    {
        return toAjax(qualityInspectionService.insertQualityInspection(qualityInspection));
    }


    /**
     * 批量新增品检
     */
    @PreAuthorize("@ss.hasPermi('depot:inspection:add')")
//    @Log(title = "品检", businessType = BusinessType.INSERT)
    @PostMapping("/batch/list")
    public AjaxResult BatchAdd(@RequestBody List<Receipt> qualityInspections)
    {
        return toAjax(qualityInspectionService.insertBatchQualityInspection(qualityInspections));
    }

    /**
     * 修改品检
     */
    @PreAuthorize("@ss.hasPermi('depot:inspection:edit')")
    @Log(title = "品检", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QualityInspectionVO qualityInspection)
    {
        return toAjax(qualityInspectionService.updateQualityInspection(qualityInspection));
    }

    /**
     * 删除品检
     */
    @PreAuthorize("@ss.hasPermi('depot:inspection:remove')")
    @Log(title = "品检", businessType = BusinessType.DELETE)
	@DeleteMapping("/{inspectionIds}")
    public AjaxResult remove(@PathVariable String[] inspectionIds)
    {
        return toAjax(qualityInspectionService.deleteQualityInspectionByInspectionIds(inspectionIds));
    }
}
